package com.donn.securitycontrolplatform.roletag.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.db1.mapper.TRoleTagMapper;
import com.donn.securitycontrolplatform.roletag.entity.TRoleTag;
import com.donn.securitycontrolplatform.roletag.service.ITRoleTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-10
 */
@Service
@Slf4j
public class ITRoleTagServiceImpl extends ServiceImpl<TRoleTagMapper, TRoleTag> implements ITRoleTagService {
    /**
     * 新增角色标签
     * @param roleTag 角色标签实体
     * @return 新增结果
     */
    @Override
    public Result insertRoleTag(TRoleTag roleTag) {
        try {
            if (save(roleTag)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("insert error :", e);
        }
        return Result.init(500, "fail", "");
    }

    /**
     * 更新角色标签
     * @param roleTag 角色id;标签id
     * @return 更新结果
     */
    @Override
    public Result updateRoleTag(TRoleTag roleTag) {
        try {
            if (updateById(roleTag)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("update error :", e);
        }
        return Result.init(500, "fail", "");
    }

    /**
     * 删除角色
     * @param roleId 角色id
     * @return 删除结果
     */
    @Override
    public Result deleteRoleTag(Long roleId) {
        try {
            if (removeById(roleId)) {
                return Result.success("");
            }
        } catch (Exception e) {
            log.error("delete error :", e);
        }
        return Result.init(500, "fail", "");
    }

    /**
     * 角色，标签关联详情
     * @param roleId 角色id
     * @return
     */
    @Override
    public Result getRoleTagById(Long roleId) {
        try {
            QueryWrapper<TRoleTag> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(TRoleTag::getRoleId, roleId);
            return Result.success(list(queryWrapper));
        } catch (Exception e) {
            log.error("delete error :", e);
        }
        return Result.init(500, "fail", "");
    }
}
